package com.coocaa.ops.admin.v1.buttonmanage.converter;

import com.coocaa.ops.common.core.biz.auth.entity.SysRunEntity;

import java.util.Iterator;
import java.util.List;

/**
 * @author bijiahao
 * @date : 2019/9/26.
 * @description
 */
public final class ButtonManageConverter {

    public static List<SysRunEntity> removeButton(List<SysRunEntity> buttons, List<SysRunEntity> retainButtons) {
        if (buttons == null || retainButtons == null) {
            return buttons;
        }
        Iterator<SysRunEntity> it = buttons.iterator();
        while (it.hasNext()) {
            SysRunEntity sysRunEntity = it.next();
            if (!isRetainSysRun(sysRunEntity, retainButtons)) {
                it.remove();
            }
        }
        return buttons;
    }

    private static boolean isRetainSysRun(SysRunEntity sysRunEntity, List<SysRunEntity> retainButtons) {
        for (SysRunEntity temp : retainButtons) {
            if (sysRunEntity.getId().equals(temp.getId())) {
                return true;
            }
        }
        return false;
    }
}
